<?php

	/**
	 * QiuXiangCheng
	 * 部门相关模型
	 */
	class Base_Model_Department extends Model_Base{

		/**
		 * 取指定部门信息
		 * @param 部门ID
		 * @param 是否以ID作为键返回
		 * @return Array();
		 */
		public function getDepartment($did = 0, $pk = 0){

			$where = $did ? $where = ' WHERE id = ' . $did : '';
			$depts = $this -> db() -> fetchAll('SELECT id, department_name FROM c_warehouse_dept' . $where);
			if($pk !== 0){
				foreach($depts as $values){
					$temp[$values['id']] = $values;
				}
			}else{
				$temp = $depts;
			}
			return $temp;
		}

		/**
		 * 输出HTML形式的部门列表
		 * @return (string)
		 */
		public function gertDepartmentHTML($data){

			$str = '';
			foreach($data as $values){
				$str .= '<option value="' . $values['id'] . '">' . $values['department_name'] . '</option>';
			}
			return $str;
		}
	}